<?php $count = 0; foreach( $names as $name){ $count = $count + 1; echo "<td>".$count. "</td> "<td>".$name. "</td>"; } echo $count; ?>